/**
 * 
 */
package com.aihwcm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aihwcm.entity.Aihappendixes;
import com.aihwcm.entity.AihappendixesDAO;
import com.aihwcm.entity.Aihdocuments;
import com.aihwcm.entity.AihdocumentsDAO;

/**
 * @author francisli
 *
 */
@Component("AppendixManageService")
public class AppendixManageServiceImpl implements AppendixManageService {

	@Autowired(required = false)
	private AihdocumentsDAO aihdocumentsDAO;
	@Autowired(required = false)
	private AihappendixesDAO aihappendixesDAO;

	@Override
	public void saveAppendix(Aihappendixes appendix) {

		aihappendixesDAO.save(appendix);

	}

	@Override
	public void delAppendix(int docid) {

		Aihdocuments aihdocuments = aihdocumentsDAO.findById(docid);
		List<Aihappendixes> list = aihappendixesDAO.findByProperty(
				"aihdocuments", aihdocuments);
		for (Aihappendixes appendix : list) {
			aihappendixesDAO.delete(appendix);
		}

	}

	@Override
	public List<Aihappendixes> findByDocid(int docid) {

		Aihdocuments aihdocuments = aihdocumentsDAO.findById(docid);
		List<Aihappendixes> list = aihappendixesDAO.findByProperty(
				"aihdocuments", aihdocuments);
		return list;
	}
}
